/*
 *  您可以更改此项目但请不要删除作者署名谢谢，否则根据中华人民共和国版权法进行处理.
 *  You may change this item but please do not remove the author's signature,
 *  otherwise it will be dealt with according to the Copyright Law of the People's Republic of China.
 *
 *  yangbuyi Copyright (c) https://yby6.com 2024.
 */

import { defineStore } from 'pinia'


export const useChatStore =
  defineStore('chatStore', () => {

    // 定义消息集合
    const messageList = ref([])
    // 定义消息排序
    const index = ref(0)

    /**
     * 新增消息集合
     * @param message
     */
    const pushMessage = (message) => {
      console.log(message);
      messageList.value.push(message)
      console.log(messageList.value);
    }

    /**
     * 获取最后一条消息
     * @returns {number}
     */
    const getLastIndex = () => {
      return messageList.value.length
    }

    /**
     * 叠加排序
     */
    const addIndex = () => {
      index.value = index.value + 1
      return index.value
    }



    return {
      messageList,
      index,
      getLastIndex,
      pushMessage,
      addIndex
    };
  }, {
    persist: true
  });

export default useChatStore;
